//
//  SlideCollectionViewCell.m
//  Cat
//
//  Created by lushitong on 2018/12/22.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "SlideCollectionViewCell.h"
#import "FLImageView.h"

@interface SlideCollectionViewCell()

@property (nonatomic, strong) FLImageView *itemImageView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *nowLabel;
@property (nonatomic, strong) UILabel *yuanLabel;

@end

@implementation SlideCollectionViewCell

- (void)setModel:(HotsModel *)model {
	_model = model;
	[self.itemImageView setImageUrl:[NSURL URLWithString:model.mainImgUrl] size:CGSizeMake(kQKFitModuleDecimal(104), kQKFitModuleDecimal(104)) cornerRadius:kQKFitModuleDecimal(6.0)];
	self.nameLabel.text = model.title;
	self.nowLabel.text = [NSString stringWithFormat:@"￥%.2f",model.buyPrice.doubleValue];
	
	NSString *oldString = [NSString stringWithFormat:@"￥%.2f",model.marketAmount.doubleValue];
	NSMutableAttributedString *attributeMarket = [[NSMutableAttributedString alloc] initWithString:oldString];
	[attributeMarket setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)} range:NSMakeRange(0,oldString.length)];
	self.yuanLabel.attributedText = attributeMarket;
}

- (instancetype)initWithFrame:(CGRect)frame {
	self = [super initWithFrame:frame];
	if (self) {
		self.backgroundColor = [UIColor whiteColor];
		[self loadAllSubView];
	}
	return self;
}

- (void)loadAllSubView {
	
	[self.contentView addSubviews:@[self.itemImageView,self.nameLabel,self.nowLabel,self.yuanLabel]];
	
	[self.itemImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake(kQKFitModuleDecimal(104.0), kQKFitModuleDecimal(104.0)));
		make.top.equalTo(self.contentView.mas_top).offset(kQKFitModuleDecimal(20));
		make.left.equalTo(self.contentView.mas_left);
		make.right.equalTo(self.contentView.mas_right);
	}];
	
	[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.itemImageView.mas_left);
		make.top.equalTo(self.itemImageView.mas_bottom).offset(kQKFitModuleDecimal(9.0));
		make.right.lessThanOrEqualTo(self.itemImageView.mas_right);
	}];
	
	[self.nowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.nameLabel.mas_left);
		make.top.equalTo(self.nameLabel.mas_bottom);
	}];
	
	[self.yuanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.nowLabel.mas_right).offset(kQKFitModuleDecimal(3));
		make.centerY.equalTo(self.nowLabel.mas_centerY);
		make.right.lessThanOrEqualTo(self.itemImageView.mas_right);
	}];
}

#pragma mark----- lazy init -----

- (FLImageView *)itemImageView {
	if (!_itemImageView) {
		_itemImageView = [[FLImageView alloc] init];
		_itemImageView.userInteractionEnabled = NO;
	}
	return _itemImageView;
}

- (UILabel *)nameLabel {
	if (!_nameLabel) {
		_nameLabel = [UILabel labelWithFont:[UIFont systemFontOfSize:kQKFitFont(12)] textColor:COLOR_WITH_HEX(0x4A4A4A)];
	}
	return _nameLabel;
}

- (UILabel *)nowLabel {
	if (!_nowLabel) {
		_nowLabel = [UILabel labelWithFont:[UIFont boldSystemFontOfSize:kQKFitFont(14)] textColor:[UIColor blackColor]];
	}
	return _nowLabel;
}

- (UILabel *)yuanLabel {
	if (!_yuanLabel) {
		_yuanLabel = [UILabel labelWithFont:[UIFont systemFontOfSize:kQKFitFont(12)] textColor:COLOR_WITH_HEX(0xB1B1B1)];
	}
	return _yuanLabel;
}

@end
